#include <iostream>
#include <string>
#include <vector>

using namespace std;

int prefixFunction(const string& str, const string& subStr) {
    if (str.length() < subStr.length()) {
        return -1;
    }
    
    int strLen = str.size();
    int substrLen = subStr.size();
    
    vector<int> p(substrLen, 0);
    
    size_t j = 0;
    for (size_t i = 1; i < substrLen; ++i) {
        while (j > 0 && subStr[i] != subStr[j]) {
            j = p[j - 1];
        }
        if (subStr[i] == subStr[j]) {
            ++j;
        }
        p[i] = j;
    }
    
    j = 0;
    for (size_t i = 0; i < strLen; ++i) {
        while (j > 0 && subStr[j] != str[i]) {
            j = p[j - 1];
        }
        if (subStr[j] == str[i]) {
            j++;
        }
        if (j == substrLen) {
            return i - substrLen + 1;
        }
    }

    return -1;
}


int main() {
    string str, subStr;
    cin >> str >> subStr;

    cout << prefixFunction(str, subStr) << endl;

    system("pause");
    return 0;
}